package com.mapforge.map.tools.undo;

import java.util.Vector;

import javax.swing.undo.UndoManager;
import javax.swing.undo.UndoableEdit;

/**
 * This class manages a series of undoable edits, and tracks only a certain
 * maximum amount of edits.
 * 
 * @author Will Morrison
 * 
 */
public class MapForgeUndoManager extends UndoManager {
	/**
	 * Default serial version ID, here to remove warnings.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Index of current edit
	 */
	int currentIndex;

	public MapForgeUndoManager() {
		this(50);
	}

	public MapForgeUndoManager(int maxEdits) {
		super();
		this.setLimit(maxEdits);
		currentIndex = -1;
	}

	public Vector<UndoableEdit> getAllEdits() {
		return this.edits;
	}
	public synchronized void undoEditsTo(UndoableEdit edit){
		super.undoTo(edit);
	}
	public synchronized void redoEditsTo(UndoableEdit edit){
		super.redoTo(edit);
	}
	/**
	 * Removes all edits from, and including, specified index.
	 * 
	 * @param index
	 */
	/*public void discardEditsFrom(int from) {
		int diff = size() - from;
		for (int i = 0; i < diff; i++) {
			((UndoableEdit) remove(from)).die();
		}
		if (currentIndex >= size())
			currentIndex = size() - 1;
	}*/
}
